import {createRouter, createWebHistory} from 'vue-router'
//引入store
import store from '../store'
import api from '../api'
// let powerPath = [];
const routes = [
    {
        name: 'home',
        path: '/',
        meta: {
            title: '首页'
        },
        component: ()=> import('../components/Home.vue'),
        redirect: '/welcome',
        children: [
            {
                name: 'welcome',
                path: '/welcome',
                meta: {
                    title: '欢迎使用广东海洋大学人员管理系统'
                },
                component: ()=> import('../views/Welcome.vue'),
            },
            {
                name: 'user',
                path: '/system/user',
                meta: {
                    title: '用户管理'
                },
                component:()=>import('../views/User.vue'),
            },
            {
                name: 'menu',
                path: '/system/menu',
                meta: {
                    title: '菜单管理'
                },
                component:()=>import('../views/Menu.vue'),
            },
            {
                name: 'role',
                path: '/system/role',
                meta: {
                    title: '角色管理'
                },
                component:()=>import('../views/Role.vue'),
            },
            {
                name: 'dept',
                path: '/system/dept',
                meta: {
                    title: '部门管理'
                },
                component:()=>import('../views/Dept.vue'),
            },
            {
                name: 'leaves',
                path: '/system/leaves',
                meta: {
                    title: '审批管理'
                },
                component:()=>import('../views/Leaves.vue'),
            },
            {
                name: 'audit',
                path: '/audit/approve',
                meta: {
                    title: '消息管理'
                },
                component:()=>import('../views/Approve.vue')
            },
        ]
    },
    {
        name:'login',
        path: '/login',
        meta: {
            title:'登录'
        },
        component: ()=> import('../views/Login.vue')
    },
    {
        name: 'updatePassword',
        path: '/updatePassword',
        meta: {
            title: '修改密码'
        },
        component:()=>import('../views/updatePassword.vue')
    },
]
const router = createRouter({
    history: createWebHistory(),
    routes
})

router.beforeEach((to,from,next)=>{
    const paths=store.state.userInfo.path;
    if(to.path=="/updatePassword" || to.path=="/audit/approve" || to.path=="/welcome" || to.path=="/login") next()
    for(const pathsKey in paths){
        if(paths[pathsKey] === to.path){
            next();
        }
    }
})

export default router
